function [fishMat, snr, AeffWeightd]=computefishermatrix_ifo(Params, detName, lambdaVec)
%
% COMPUTEFISHERMATRIX_IFO - compute the fisher information matrix from the 3.5PN 
% accurate restricted PN waveforms in the SPA. 
%
% usage: [fishMat, snr]=computefishermatrix_ifo(Params, detName, lambdaVec)
%
% Params    - structure containing parameters totalMass and eta 
% detName   - name of the detector - LIGO/AdvLIGO/Virgo/WhiteNoise
% lambdaVec - a cell array of parameters with which the Fisher matrix should be computed. 
% 
% P. Ajith, 13.03.2008
%
% $Id: computefishermatrix_ifo.m 59 2010-01-20 21:41:01Z anand.sengupta $

setconstants

fLow = Params.fLower;

[flso] = calcflso(Params.totalMass);

if flso <= fLow 
    fishMat = [];
    warning('Fisher matrix is empty. flso < fLower')
    return
end

df = 1e-1;
fVec = [fLow:df:flso];

% the effective amplitude: A_eff(f) = C(theta, phi, psi, iota) A(f; M, eta) / dL
M = Params.totalMass*MSOLAR_TIME;
dL = Params.dL*PARSEC_SEC*1e6;
C = CalcC(Params.phi, Params.theta, Params.psi, Params.iota, Params.Det);
A = (M^(5/6))/pi^(2/3)*sqrt((5*Params.eta)/24)*fVec.^(-7/6);
Aeff = C*A/dL;

% generate noise PSD
[Sh] = detnoisepsd(detName,fVec);

% compute SNR 
AeffWeightd = Aeff.*sqrt(df)./sqrt(Sh);
snr = 2*sqrt(sum(AeffWeightd.^2));

% compute each element of the fisher matrix
for i=1:length(lambdaVec)
    for j=1:length(lambdaVec)
        
        % compute the derivatives of the phase and amplitude with respect
        % to parameter lambda_i
        [dAeffBydLamba_i] = AeffDerivative(lambdaVec{i}, fVec, Params);
        [dPsieffBydLamba_i] = PsieffDerivative(lambdaVec{i}, fVec, Params);
        
        % compute the derivatives of the phase and amplitude with respect
        % to parameter lambda_j
        [dAeffBydLamba_j] = AeffDerivative(lambdaVec{j}, fVec, Params);
        [dPsieffBydLamba_j] = PsieffDerivative(lambdaVec{j}, fVec, Params);

        % now compute the fisher matrix element by taking the noise-weighted
        % inner products
        dHidHj = dAeffBydLamba_i.*dAeffBydLamba_j + Aeff.^2.*dPsieffBydLamba_i.*dPsieffBydLamba_j;
        fishMat(i,j) = 4*df*sum(dHidHj./Sh);

    end
end








